﻿using System;
using System.Windows.Forms;
using FTPComm;

namespace ECG.UI
{
    public partial class FTPForm : Form
    {
        public FTPForm()
        {
            InitializeComponent();
        }

        private void btnd_Click(object sender, EventArgs e)
        {
            var Uri = txturi.Text.Trim();
            var filename = Uri.Substring(Uri.LastIndexOf("/") + 1);
            var filefilter = Uri.Substring(Uri.LastIndexOf(".") + 1);
            saveFileDialog1.FileName = filename;
            saveFileDialog1.Filter = filefilter + "|*." + filefilter;
            if (saveFileDialog1.ShowDialog() != DialogResult.OK) return;
            if (FTP.Download(Uri, saveFileDialog1.FileName))
            {
                MessageBox.Show("下载文件成功");
            }
        }

        private void btnopen_Click(object sender, EventArgs e)
        {
            openFileDialog1.FileName = "选择上传文件！";
            openFileDialog1.Filter = "所有文件|*.*";
            if (openFileDialog1.ShowDialog() != DialogResult.OK) return;
            txtfilename.Text = openFileDialog1.FileName;
        }

        private void btnu_Click(object sender, EventArgs e)
        {
            if (txtserverip.Text.Trim() == "" && txtfilename.Text.Trim() == "")
            {
                MessageBox.Show("服务器地址和文件地址都不能为空");
                return;
            }
            if (FTP.Upload(txtserverip.Text.Trim(), txtfilename.Text.Trim()))
                MessageBox.Show("上传文件成功！");
        }


    }
}
